using System;
using System.Collections.Generic;
using System.Text;

namespace Data.Merge
{
    class MergeStep:IComparable
    {
        private int leftson;
        private int rightson;
        private int name;
        private int hight;
        private int depth;
        int cluster;
        private bool isRoot;

        #region Constructors

        /// <summary>
        /// Leaf constructor
        /// </summary>
        /// <param name="newName"></param>
        public MergeStep(int newName)
        {
            leftson = -1;
            rightson = -1;
            name = newName;
            isRoot = true;
        }

        /// <summary>
        /// Internal node constructor
        /// </summary>
        /// <param name="newName"></param>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <param name="newHigth"></param>
        public MergeStep(int newName, int left, int right,int newHigth)
        {
            leftson = left;
            rightson = right;
            name = newName;
            hight = newHigth;
            isRoot = true;
        }

        #endregion

        #region Properties

        public int ClusterNum
        {
            set { cluster = value; }
            get { return cluster; }
        }
        public bool IsRoot
        {
            get { return isRoot; }
            set { isRoot = value; }
        }

        public int Hight
        {
            set { hight = value; }
            get { return hight; }
        }

        public int Depth
        {
            set { depth = value; }
            get { return depth; }
        }

        public int Leftson
        {
            get { return leftson; }
        }

        public int Rightson
        {
            get { return rightson; }
        }

        public int Name
        {
            get { return name; }
        }

        #endregion

        #region Methods

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Boolean hasLeftSon()
        {
            if (leftson != -1)
                return true;
            return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Boolean hasRightSon()
        {
            if (rightson != -1)
                return true;
            return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Boolean isLeaf()
        {
            if ((rightson != -1) || (rightson != -1))
                return false;
            return true;
        }

        public override string ToString()
        {
            if ((leftson != -1) && (rightson != -1))
                return '(' + leftson.ToString() + ", " + rightson.ToString() + ')' + name.ToString()+"\n";
            else
                return name.ToString()+"\n";
        }

        #endregion

        #region IComparable Members

        public int CompareTo(object obj)
        {
            if (obj is MergeStep)
            {
                if (this.name > ((MergeStep)obj).name)
                    return 1;
                if (this.name < ((MergeStep)obj).name)
                    return -1;
            }
            return 0;
        }

        #endregion
        //delete this row
    }
}

